
/*-----------------------------------------------File Info------------------------------------------------
** File Name:               usrTask.c  
** Last modified date:      2016.07.22
** Last version:            V0.1
** Description:             
**--------------------------------------------------------------------------------------------------------            
** Created date:            2016.09.07
** author:                  YLY
** Version:                 V0.1
** Descriptions:            任务1 
**--------------------------------------------------------------------------------------------------------
*/

/*************************************************************
* 	include 
* 	头文件	
*************************************************************/ 

#include "ctrl.h"
#include "mainTask.h"
#include "key.h"
#include "arithmetic.h"

uint32_t getRelaySta(void)
{
	uint32_t bit32 = 0;
	
	bit32 |= (uint32_t)RELAYx_GET(RELAY1);
	bit32 |= ((uint32_t)RELAYx_GET(RELAY2)) << 1;
	bit32 |= ((uint32_t)RELAYx_GET(RELAY3)) << 2;
	bit32 |= ((uint32_t)RELAYx_GET(RELAY4)) << 3;
	return bit32;
}

void setRelaySta(uint32_t vol)
{
	RELAYx_SET(RELAY1,vol & BIT(0));
	RELAYx_SET(RELAY2,vol & BIT(1));
	RELAYx_SET(RELAY3,vol & BIT(2));
	RELAYx_SET(RELAY4,vol & BIT(3));	
}

//---------主机复位-----------
void hostReset(void)
{
	MAIN_DBG("\r\n\r\nPowerRst!!!!\r\n\r\n");	

	RESET_PMU_START();
	osDirectiveDelayMs(100);
	RESET_PMU_STOP();

	/* enable IRC40K */
	rcu_osci_on(RCU_IRC40K);
	/* wait till IRC40K is ready */
	rcu_osci_stab_wait(RCU_IRC40K);	

	/* enable write access to FWDGT_PSC and FWDGT_RLD registers.
	   FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz =1.6mS */
	fwdgt_config(1,FWDGT_PSC_DIV64);
	fwdgt_enable();
	__NVIC_SystemReset();
	//nvic_system_reset();	//	直接复位跳转到bootload
	/* 复位MCU */
	while(1)
	{
		__NOP();
	}
	
}


/**
*	function:	获取随机数
*	作用:	 
*	return :	no
*	返回:	
**/
uint8_t getRandomNumber(void) 
{
	uint8_t a;
	static uint8_t b;
	do
	{
		a = (uint8_t)getSysTickVal();
	}while(b == a);
	b = a;
	return a;
}

